package model;

import java.io.Serializable;
import java.util.ArrayList;

import exception.GameException;

public class HoldEmGame extends Game implements Serializable
{
	protected ArrayList<HoldEmTable> tables = new ArrayList<HoldEmTable>();
	
	public HoldEmGame()
	{
		
	}

	public HoldEmGame(GameType gameType, GameStake gameStake, int buyin, int seats) throws GameException
	{
		super(GameVariant.HOLD_EM, gameType, gameStake, buyin, seats);
	}
	
	protected int determineSmallBlind()
	{
		switch (gameType)
		{
			case SINGLE_TABLE:

				// smallBlind = 40;
				
				break;
			
			case CASH_GAME:

				break;
			
			case TOURNAMENT:

				break;
		}
		
		return 20;
	}
	
	public GameType getGameType()
	{
		return gameType;
	}
	
	protected void openBody()
	{
		
	}
	
	public void startBody() throws GameException
	{
		for (HoldEmTable table: tables)
		{
			table.start();
		}
	}
	
	private Table getJoinTableSingle() throws GameException
	{
		HoldEmTable table;
		
		if (tables.size() == 0)
		{
			table = new HoldEmTable(seats);
			
			table.setGame(this);
			
			tables.add(table);
		}
		else
		{
			table = tables.get(0);
			
			table.checkSeatsTaken(true);
		}
		
		return table;
	}
	
	private Table getJoinTableMultiple()
	{
		// TODO: Ivo will think of a way to evenly divide the players over the
		// tables.
		return null;
	}
	
	public Table getJoinTable() throws GameException
	{
		switch (gameType)
		{
			case SINGLE_TABLE:

				return getJoinTableSingle();
				
			case CASH_GAME:

				return getJoinTableSingle();
				
			case TOURNAMENT:

				return getJoinTableMultiple();
		}
		
		return null;
	}
	
	public boolean shouldStart()
	{
		switch (gameType)
		{
			case SINGLE_TABLE:
			case TOURNAMENT:

				if (participants.size() == seats)
				{
					return true;
				}
				
				break;
			
			case CASH_GAME:

				if (participants.size() > 2)
				{
					return true;
				}
				
				break;
		}
		
		return false;
	}
}
